#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
"""
@author:Gwong Zaak Liu
@interpreter version:python 3.8.13
@file:  main.py
@time:  2022/10
"""

import random
import requests

# 随机抽取的UserAgent列表
UserAgentList = ['Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14',
                 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0) Opera 12.14',
                 'Opera/9.80 (Windows NT 6.1; U; es-ES) Presto/2.9.181 Version/12.00',
                 'Mozilla/5.0 (Windows NT 5.1) Gecko/20100101 Firefox/14.0 Opera/12.0',
                 'Opera/9.80 (Windows NT 6.0; U; pl) Presto/2.10.229 Version/11.62',
                 'Opera/9.80 (Windows NT 5.1; U; en) Presto/2.9.168 Version/11.51',
                 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; de) Opera 11.51',
                 'Opera/9.80 (Windows NT 5.1; U; zh-tw) Presto/2.8.131 Version/11.10',
                 'Opera/9.80 (X11; Linux i686; U; ja) Presto/2.7.62 Version/11.01',
                 'Opera/9.80 (Windows NT 6.1; U; zh-cn) Presto/2.7.62 Version/11.01']


def TestResponseCode(url):
    headers = {'User-Agent': random.sample(UserAgentList, 1)[0]}
    # print(headers)
    try:
        response = requests.get(url, headers=headers, timeout=5)
        response.encoding = "utf-8"
        return str(response)
    except requests.exceptions.RequestException as e:
        return e.response
